<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Using the Integrated Ant Task</title>
  <link type="text/css" rel="stylesheet" href="../mbgdoc/mbgstyle.css"/>
</head>
<body>
<h1>Using the Integrated Ant Task</h1>
<p>The MyBatis Generator feature includes an integrated Ant task for
running MyBatis generator.  This Ant task is different from the Ant task
included in the basic MyBatis Generator distribution in that it supports
Java file merging, and is integrated with the eclipse user
interface, logging system, and progress notification system.</p>
<p>It is useful to use the integrated Ant task in the following situations:</p>
<ul>
  <li>When you want to automate a generation run, and support merging Java files.
    In this case, you should setup an Ant build as demonstrated below, then
    use an Eclipse headless Ant build to run the generator automatically.
    The standard eclipse help includes directions for running a headless
    Ant build.  Search in the Eclipse help for the word "headless".</li>
  <li>When you want to provide a custom implementation of one of the
   core MyBatis generator interfaces.  For example, if you want to provide
   a custom implementation of the JavaTypeResolver interface.  When running
   MyBatis Generator from the simple menu option, you have no control over
   the classpath of the run.  When you run from Ant, you have much more
   control over the runtime classpath.</li>
</ul>

<h2>Integrated Ant Task Detail</h2>
<p>The plug-in declares an Ant task for use within the Eclipse JRE.  The
  task is called "mybatis.generate".  Here is an example Ant build file:</p>

<pre>
&lt;project default="runMyBatisGenerator"&gt;
  &lt;target name="runMyBatisGenerator"&gt;
    &lt;eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                         property="thePath"/&gt;
    &lt;mybatis.generate configfile="${thePath}" /&gt;
  &lt;/target&gt;
&lt;/project&gt;
</pre>
<p>This file uses the Eclipse supplied "eclipse.convertPath" task to calculate the
 actual path of the configuration file.  Then we use the
 "mybatis.generate" task to run MyBatis Generator.  When running
 this from Eclipse interactively,
 the Ant launch must be setup to run in the same JRE as the workspace.
 This setting is a standard configuration setting for running Ant in Eclipse.
</p>
<p>The task supports an optional nested <code>&lt;propertyset&gt;</code> element which
  is the standard Ant property set type.  This can be used to pass parameters into
  a configuration file.</p>

<p>The integrated Ant task supports the following attributes:</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">configfile</td>
    <td>This is the configuration file to use.  Use the "eclipse.convertPath"
     task to convert a workspace path to an absolute path before setting this
     attribute (as shown above)
     <p>This attribute is required.</p></td>
  </tr>
  <tr>
    <td valign="top">contextIds</td>
    <td>If specified, then this is a comma delimited list of contexts to use in
      the current run of the generator.  Any id specified in the list must exactly
      match the value of the <code>id</code> attribute of a
      &lt;context&gt; configuration element.  Only ids specified
      in this list will be active for this run.  If this attribute
      is not specified, then all contexts will be active.</td>
  </tr>
<tr>
  <td valign="top">fullyQualifiedTableNames</td>
  <td>If specified, then this is a comma delimited list of tables to use in
      the current run of the generator.  Any table specified in the list must exactly
      match the fully qualified table name specified in a
      &lt;table&gt; configuration element.  Only tables specified
      in this list will be active for this run.  If this attribute
      is not specified, then all tables will be active.
      Specify table names as: <br/><br/>
      <code>table</code><br/>
      <code>schema.table</code><br/>
      <code>catalog..table</code><br/>
      etc.</td>
</tr>
</table>
</body>
</html>
